{% extends 'contact.html' %}
{% block static %}
    <link rel="stylesheet" href="{% static 'css/login.css' %}">
{% endblock %}
{% block body %}
    <div class="materialContainer">
        <div class="box">
            <div class="title">登录</div>
            <div class="input">
                <label for="name">用户名</label>
                <input type="text" name="name" id="name">
                <span class="spin"></span>
            </div>
            <div class="input">
                <label for="pass">密码</label>
                <input type="password" name="pass" id="pass">
                <span class="spin"></span>
            </div>
            <div class="button login">
                <button id="user_login">
                    <span>登录</span>
                    <i class="fa fa-check"></i>
                </button>
            </div>
            <a href="javascript:" class="pass-forgot" id="forget_password">忘记密码？</a>
        </div>

        <div class="overbox">
            <div class="material-button alt-2">
                <span class="shape"></span>
            </div>
            <div class="title">注册</div>
            <div class="input">
                <label for="regname">用户名(请使用真实姓名当做账号)</label>
                <input type="text" name="regname" id="regname">
                <span class="spin"></span>
            </div>
            <div class="input">
                <label for="regpass">密码</label>
                <input type="password" name="regpass" id="regpass">
                <span class="spin"></span>
            </div>
            <div class="input">
                <label for="reregpass">确认密码</label>
                <input type="password" name="reregpass" id="reregpass">
                <span class="spin"></span>
            </div>
            <div class="button">
                <button class="user_register">
                    <span>注册</span>
                </button>
            </div>
        </div>
    </div>
    <script src="{% static 'js/login.js' %}"></script>
    <script>
        $('.user_register').click(function () {
            let regname = $('#regname').val();
            let regpass = $('#regpass').val();
            let reregpass = $('#reregpass').val();
            console.log(regname, regpass, reregpass);
            if (regname != '' & regpass != '' & reregpass != '') {
                if (regpass == reregpass) {
                    $.ajax({
                        url: "{% url 'myadmin:User_Register' %}",//路径
                        type: "POST", //提交方式
                        data: {"regname": regname, 'regpass': regpass},
                        success: function (result) {//返回数据根据结果进行相应的处理
                            if (result.code = 200) {
                                layer.msg(result.message);
                                setTimeout(sleep, 1000);
                            }
                        },
                        error: function (error) {
                            layer.msg("500，请稍后尝试")
                        }
                    });
                } else {
                    layer.msg('小主，两次输入密码不一致')
                }
            } else {
                layer.msg('小主，仔细看看是否有漏掉未填写的哦')
            }
        });

        //定义一个函数
        function sleep() {
            window.location.reload();
        }
        $('#user_login').click(function () {
            let name = $('#name').val();
            let pass = $('#pass').val();
            console.log(name,pass);
            if (name!= '' & pass != '' ) {
                $.ajax({
                    url: "{% url 'myadmin:User_Login' %}",//路径
                    type: "POST", //提交方式
                    data: {"name": name, 'pass': pass},
                    success: function (result) {//返回数据根据结果进行相应的处理
                        console.log(result.code);
                        if (result.code == 400) {
                            layer.msg(result.message);
                        } else if (result.code = 200) {
                            layer.msg(result.message);
                            setTimeout("window.location.href='/upload_file/'",1000);
                        }
                    },
                    error: function (error) {
                        layer.msg("500，请稍后尝试")
                    }
                });
            } else {
                xtalert.alertError("小主,你是不是漏记填写账号或者密码")
            }
        });

        // 忘记密码提醒
        $('#forget_password').click(function() {
            xtalert.alertErrorToast("请联系项目开发者")
        })


    </script>
{% endblock %}